package cn.mumzone.pos.ui.adapter.inventory;

import android.content.Context;
import android.view.View;

import cn.mumzone.basic.adapter.rv.CommonAdapter;
import cn.mumzone.basic.adapter.rv.ViewHolder;
import cn.mumzone.basic.util.AppDateUtil;
import cn.mumzone.pos.R;
import cn.mumzone.pos.model.InventoryItemEntity;

/**
 * Created By Dlx
 * on 2019/9/25
 */
public class ADA_InventoryItem extends CommonAdapter<InventoryItemEntity> {

    private OnCardClickListener listener;

    public ADA_InventoryItem(Context context) {
        super(context);
    }

    @Override
    protected int itemLayoutId() {
        return R.layout.item_inventory_card;
    }

    public void setOnCardClickListener(OnCardClickListener listener) {
        this.listener = listener;
    }

    @Override
    protected void convert(ViewHolder holder, final InventoryItemEntity inventoryItemEntity, int position) {

        holder.setText(R.id.tv_name, inventoryItemEntity.getUserName());
        holder.setText(R.id.tv_inventory_id, inventoryItemEntity.getInventoryCode());
        holder.setText(R.id.tv_storehouse, inventoryItemEntity.getWarehouseName());
        holder.setText(R.id.tv_type, getInventoryType(inventoryItemEntity.getInventoryType()));
        holder.setText(R.id.tv_date, AppDateUtil.getTimeStamp(inventoryItemEntity.getCreateTime(), AppDateUtil.YYYY_MM_DD_HH_MM));
        holder.setText(R.id.tv_status, getInventoryStatus(inventoryItemEntity.getInventoryStatus()));

        holder.setOnClickListener(R.id.cv_root, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onCardClick(inventoryItemEntity.getId(), inventoryItemEntity.getInventoryStatus());
                }
            }
        });

    }

    private String getInventoryType(String type) {
        if ("0".equals(type))
            return "日盘";
        if ("1".equals(type))
            return "周盘";
        if ("2".equals(type))
            return "月盘";
        return "错误类型" + type;
    }

    private String getInventoryStatus(String type) {
        if ("0".equals(type))
            return "未开始";
        if ("1".equals(type))
            return "进行中";
        if ("2".equals(type))
            return "进行中";
        if ("3".equals(type))
            return "已完成";
        if ("4".equals(type))  //已驳回 也是进行中
            return "进行中";
        return "错误类型" + type;
    }

    public interface OnCardClickListener {
        void onCardClick(String id, String inventoryStatus);
    }
}
